/**
 * Copyright 2019-2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <iostream>
#include <list>
#include "common/comm_error_codes.h"

#define protected public
#define private public
#include "common/configuration.h"
#include "common/util/json_util.h"
#include "common/util/constants.h"
#include "common/common_utils.h"
#include "graph/ge_context.h"
#include "ge/ge_api_types.h"
#include "common/aicore_util_constants.h"
#include "fusion_config_manager/fusion_config_parser.h"
#undef private
#undef protected

using namespace std;
using namespace fe;

class configuration_ut: public testing::Test
{
protected:
    void SetUp()
    {
        Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
        config.is_init_ = false;
        map<string, string> options;
        string soc_version = "Ascend310";
        config.Initialize(options, soc_version);
    }

    void TearDown()
    {
        Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
        config.is_init_ = false;
        map<string, string> options;
        string soc_version = "Ascend310";
        config.Initialize(options, soc_version);
    }
// AUTO GEN PLEASE DO NOT MODIFY IT
};

namespace{
std::string GetConfigFilePathStub(Configuration *This)
{
    std::string config_file_path = "/home/fe_config/fe.ini";
    return config_file_path;
}

ge::graphStatus GetOptionTrue(ge::GEContext *This, const std::string &key, std::string &option)
{
  option = "1";
  return ge::GRAPH_SUCCESS;
}

ge::graphStatus GetOptionFalse(ge::GEContext *This, const std::string &key, std::string &option)
{
  option = "0";
  return ge::GRAPH_SUCCESS;
}

ge::graphStatus GetOptionEmpty(ge::GEContext *This, const std::string &key, std::string &option)
{
  option = "";
  return ge::GRAPH_SUCCESS;
}
ge::graphStatus GetOptionFail(ge::GEContext *This, const std::string &key, std::string &option)
{
  option = "0";
  return ge::GRAPH_FAILED;
}
std::string GetBuiltInConfigFilePathStubs(Configuration *This)
{
  return "./air/test/engines/nneng/ut/testcase/fusion_engine/fusion_manager/fusion_switch_build_in";
}

}

TEST_F(configuration_ut, get_boolvalue)
{
    bool bool_value = Configuration::Instance(fe::AI_CORE_NAME).GetBoolValue("needl2fusion", false);
    ASSERT_FALSE(bool_value);
}

TEST_F(configuration_ut, get_boolvalue_abnormal)
{
    Configuration::Instance(fe::AI_CORE_NAME).content_map_.emplace("needl2fusion2", "!@##$");
    bool bool_value = Configuration::Instance(fe::AI_CORE_NAME).GetBoolValue("needl2fusion2", false);
    ASSERT_FALSE(bool_value);
}

TEST_F(configuration_ut, loadconfigfile_success)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend310";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    Status status = config.LoadConfigFile();
    EXPECT_EQ(status, SUCCESS);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend310";
    config.Initialize(options, soc_version);
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success1)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Ascend310";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "ascend310";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success2)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Ascend610";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "ascend610";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success3)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Ascend910A";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "ascend910";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success4)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Ascend910B";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "ascend910";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success5)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Hi3796CV300ES";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "hi3796cv300es";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_success6)
{
    Configuration& config = Configuration::Instance(fe::AI_CORE_NAME);
    config.soc_version_ = "Hi3796CV300CS";
    config.content_map_.clear();
    config.content_map_.emplace("op.store.tbe-builtin", "2|6|op_impl/built-in/ai_core/tbe/config|op_impl/built-in/ai_core/tbe/impl/|true|true");
    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, SUCCESS);
    FEOpsStoreInfo op_store_info;
    config.GetOpStoreInfoByImplType(EN_IMPL_HW_TBE, op_store_info);
    string sub_path = "hi3796cv300cs";
    int32_t pos = op_store_info.cfg_file_path.rfind(sub_path);
    EXPECT_EQ(pos, op_store_info.cfg_file_path.length()-sub_path.length());
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed1)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.", "1|1|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_NAME_EMPTY);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed2)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_VALUE_EMPTY);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed3)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "0|0|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_VALUE_ITEM_SIZE_INCORRECT);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed4)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|1|./config/fe_config/tik_custom_opinfo|x|qwer|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_VALUE_ITEM_SIZE_INCORRECT);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed5)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|1|./config/fe_config/tik_custom_opinfo||false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_VALUE_ITEM_EMPTY);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed6)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|1||./config/fe_config/tik_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_VALUE_ITEM_EMPTY);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed7)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_EMPTY);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed8)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "x|1|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_PRIORITY_INVALID);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed9)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|c|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_OPIMPLTYPE_INVALID);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed10)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|15|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_OPIMPLTYPE_INVALID);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed11)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|-1|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_OPIMPLTYPE_INVALID);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed12)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "1|2|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tdk-custom", "2|2|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_OPIMPLTYPE_REPEAT);
}

TEST_F(configuration_ut, AssembleOpsStoreInfoVector_failed13)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend610";
    config.Initialize(options, soc_version);
    config.content_map_.clear();
    config.content_map_.emplace("op.store.cce-custom", "0|0|./config/fe_config/cce_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");
    config.content_map_.emplace("op.store.tik-custom", "0|2|./config/fe_config/tik_custom_opinfo|./config/fe_config/cce_custom_opinfo|false|false");

    Status status = config.AssembleOpsStoreInfoVector();
    EXPECT_EQ(status, OPSTORE_PRIORITY_INVALID);
}

TEST_F(configuration_ut, get_opsstoreinfo)
{
    Configuration::Instance(fe::AI_CORE_NAME).is_init_ = false;
    vector<FEOpsStoreInfo> ops_store_info_vec = Configuration::Instance(fe::AI_CORE_NAME).GetOpsStoreInfo();
    EXPECT_EQ(ops_store_info_vec.size(), 2);

    for (FEOpsStoreInfo &op_store_info : ops_store_info_vec)
    {
        if (op_store_info.op_impl_type == EN_IMPL_HW_TBE)
        {
            EXPECT_EQ(op_store_info.fe_ops_store_name, "tbe-builtin");
        }
        if (op_store_info.op_impl_type == EN_IMPL_VECTOR_CORE_HW_TBE)
        {
            EXPECT_EQ(op_store_info.fe_ops_store_name, "vectorcore-tbe-builtin");
            EXPECT_EQ(op_store_info.need_pre_compile, true);
            EXPECT_EQ(op_store_info.need_compile, false);
        }
        if (op_store_info.op_impl_type == EN_IMPL_VECTOR_CORE_CUSTOM_TBE)
        {
            EXPECT_EQ(op_store_info.fe_ops_store_name, "vectorcore-tbe-builtin");
            EXPECT_EQ(op_store_info.need_pre_compile, true);
            EXPECT_EQ(op_store_info.need_compile, true);
        }
        if (op_store_info.op_impl_type == EN_IMPL_PLUGIN_TBE)
        {
            EXPECT_EQ(op_store_info.need_pre_compile, true);
            EXPECT_EQ(op_store_info.need_compile, false);
        }
    }
}

TEST_F(configuration_ut, getstringvalue_success)
{
    string stringvalue;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetStringValue("fusionrulemgr.multireferswitch", stringvalue);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(stringvalue, "yes");
}

TEST_F(configuration_ut, getstringvalue_failed)
{
    string stringvalue;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetStringValue("fusionrulemgr.xxx", stringvalue);
    EXPECT_EQ(status, FAILED);
}

TEST_F(configuration_ut, GetOpStoreInfoByImplType_success)
{
    FEOpsStoreInfo op_store_info;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetOpStoreInfoByImplType(EN_IMPL_CUSTOM_TBE, op_store_info);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(op_store_info.fe_ops_store_name, "tbe-custom");
}

TEST_F(configuration_ut, GetOpStoreInfoByImplType_failed)
{
    FEOpsStoreInfo op_store_info;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetOpStoreInfoByImplType(EN_RESERVED, op_store_info);
    EXPECT_EQ(status, FAILED);
}

TEST_F(configuration_ut, getgraphfilepath)
{
    string graph_file_path;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetGraphFilePath(graph_file_path);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(graph_file_path, "");
}

TEST_F(configuration_ut, getcustomfilepath)
{
    string custom_file_path;
    Status status = Configuration::Instance(fe::AI_CORE_NAME).GetCustomFilePath(custom_file_path);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(custom_file_path, "");
}

TEST_F(configuration_ut, get_appendargsmode_1910)
{
    Configuration config(fe::AI_CORE_NAME);
    map<string, string> options;
    string soc_version = "Ascend310";
    
    config.Initialize(options, soc_version);
    AppendArgsMode lm = config.GetAppendArgsMode();
    EXPECT_EQ(lm, L2_BUFFER_ARGS);
}

TEST_F(configuration_ut, get_opsstoreinfo_vectorcore)
{
  Configuration config(fe::VECTOR_CORE_NAME);
  map<string, string> options;
  string soc_version = "Ascend610";
  config.Initialize(options, soc_version);
  vector<FEOpsStoreInfo> ops_store_info_vec = config.GetOpsStoreInfo();
  EXPECT_EQ(ops_store_info_vec.size(), 2);

  for (FEOpsStoreInfo &op_store_info : ops_store_info_vec)
  {
    if (op_store_info.op_impl_type == EN_IMPL_VECTOR_CORE_HW_TBE)
    {
      EXPECT_EQ(op_store_info.fe_ops_store_name, "vectorcore-tbe-builtin");
      EXPECT_EQ(op_store_info.need_pre_compile, true);
      EXPECT_EQ(op_store_info.need_compile, true);
    }
    if (op_store_info.op_impl_type == EN_IMPL_VECTOR_CORE_CUSTOM_TBE)
    {
      EXPECT_EQ(op_store_info.fe_ops_store_name, "vectorcore-tbe-custom");
      EXPECT_EQ(op_store_info.need_pre_compile, true);
      EXPECT_EQ(op_store_info.need_compile, true);
    }
  }
}

TEST_F(configuration_ut, getgraphfilepath_vectorcore)
{
  string graph_file_path;
  Configuration config(fe::VECTOR_CORE_NAME);
  map<string, string> options;
  string soc_version = "Ascend610";
  config.Initialize(options, soc_version);
  Status status = config.GetGraphFilePath(graph_file_path);
  EXPECT_EQ(status, SUCCESS);
  EXPECT_EQ(graph_file_path, "");
}

TEST_F(configuration_ut, getcustomfilepath_vectorcore)
{
  string custom_file_path;
  Configuration config(fe::VECTOR_CORE_NAME);
  map<string, string> options;
  string soc_version = "Ascend610";
  config.Initialize(options, soc_version);
  Status status = config.GetCustomFilePath(custom_file_path);
  EXPECT_EQ(status, SUCCESS);
  EXPECT_EQ(custom_file_path, "");
}

TEST_F(configuration_ut, InitBufferFusionMode_offOptimize2)
{
    Configuration config(AI_CORE_NAME);
    config.is_init_ = false;
    config.content_map_.emplace("l2fusion.enable", "false");
    map<string, string> options;
    options.emplace("ge.bufferOptimize", "off_optimize");
    Status status = config.InitOptions(options);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(config.EnableL1Fusion(), false);
    EXPECT_EQ(config.buffer_optimize_, EN_OFF_OPTIMIZE);

    config.InitBufferFusionMode();
    EXPECT_EQ(config.GetBufferFusionMode(), EN_OPTIMIZE_DISABLE);
}

TEST_F(configuration_ut, InitBufferFusionMode_offOptimize3)
{
    Configuration config(AI_CORE_NAME);
    config.is_init_ = false;
    config.content_map_.emplace("l2fusion.enable", "true");
    map<string, string> options;
    options.emplace("ge.bufferOptimize", "off_optimize");
    Status status = config.InitOptions(options);
    EXPECT_EQ(status, SUCCESS);
    EXPECT_EQ(config.EnableL1Fusion(), false);
    EXPECT_EQ(config.buffer_optimize_, EN_OFF_OPTIMIZE);

    config.InitBufferFusionMode();
    EXPECT_EQ(config.GetBufferFusionMode(), EN_OPTIMIZE_DISABLE);
}

TEST_F(configuration_ut, InitBufferFusionMode_else) {
    Configuration config(AI_CORE_NAME);
    config.is_init_ = false;
    config.content_map_.emplace("l2fusion.enable", "true");
    map<string, string> options;
    options.emplace("ge.bufferOptimize", "off_optimize");
    Status status = config.InitOptions(options);
    EXPECT_EQ(status, SUCCESS);
  GetBufferOptimizeString(EN_L1_OPTIMIZE);
  GetBufferFusionModeString(EN_OPTIMIZE_DISABLE);
}

TEST_F(configuration_ut, InitBufferFusionMode_invalid_buffer_optimize)
{
    Configuration config(AI_CORE_NAME);
    config.is_init_ = false;
    map<string, string> options;
    options.emplace("ge.bufferOptimize", "xxx");
    string soc_version = "Ascend310";
    Status status = config.Initialize(options, soc_version);
    EXPECT_EQ(status, FAILED);
    EXPECT_EQ(config.buffer_optimize_, EN_UNKNOWN_OPTIMIZE);
    EXPECT_EQ(config.GetBufferFusionMode(), EN_OPTIMIZE_DISABLE);
    EXPECT_EQ(config.EnableL1Fusion(), false);
}
